package com.brkj.download;

import java.lang.reflect.Type;
import java.util.List;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.annotation.view.ViewInject;
import net.tsz.afinal.http.AjaxCallBack;
import com.brkj.httpInterface.BaseAjaxParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.brkj.course.CourseDetailActivity;
import com.brkj.model.DS_Comment;
import com.brkj.main.R;
import com.brkj.httpInterface.HttpInterface.HIF_GetCoumment;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


public class DLCourseDetailActivity extends CourseDetailActivity{

	@ViewInject(id=R.id.commentListView) ListView commentListView;
	@ViewInject(id=R.id.commentEdit) EditText commentEdit;
	@ViewInject(id=R.id.submit,click="submitComment") Button submit;
	
	@Override
	protected void getComment(String CourseID) {
		BaseAjaxParams params = new BaseAjaxParams();
		params.put(HIF_GetCoumment.params.CourseID, CourseID);
		
		FinalHttp fh = new FinalHttp();
		fh.post(HIF_GetCoumment.address, params, new AjaxCallBack<Object>() {
			
			

			@Override
			public void onFailure(Throwable t, String strMsg) {
				// TODO Auto-generated method stub
				super.onFailure(t, strMsg);
				showToast("离线状态，无法获取评论！");
			}

			@Override
			public void onSuccess(Object t) {
				super.onSuccess(t);
				
//				HIF_GetCourse.result result = JsonUtil.fromJson((String)t, HIF_GetCourse.result.class);
				
				Gson gson = new Gson();
				Type listType = new TypeToken<List<DS_Comment>>(){}.getType();
				commentList  = gson.fromJson((String)t, listType);
				
				if(commentList != null){
					getView(commentList);
				}
				
			}
			
		});
	}


	
}
